package com.example.ioccontainer.task;

import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class TimerTask {

    private static final DateTimeFormatter formatter =
            DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public void printCurrentTime() {
        String currentTime = LocalDateTime.now().format(formatter);
        System.out.println("当前时间: " + currentTime);
    }

    public void countdownOneMinute() {
        System.out.println("开始60秒倒计时...");
        for (int i = 60; i >= 0; i--) {
            System.out.println("倒计时: " + i + " 秒");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("倒计时结束!");
    }
}
